package service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import domain.Page;
import domain.Standard;
import mapper.StandardMapper;

@Service
public class StandardService {
	@Autowired
	private StandardMapper mapper;
	
	public List<Standard> getAll(){
		return mapper.selectAll();
	}
	public boolean insert(Standard s) {
		int result = mapper.insert(s);
		return result==0 ? false:true;
	}
	public int getCount() {
		return mapper.getCount();
	}
	// 分页查询某一页数据
	public Page<Standard> findPage(Integer page, Integer size) {
		int total = mapper.getCount();
		
		List<Standard> items = mapper.selectPage((page - 1) * size, size);
		
		Page<Standard> pageData = new Page<>();
		pageData.setTotal(total);
		pageData.setItems(items);
		
		return pageData;
	}
	public boolean delete(Standard s) {
		if(s==null) {
			return false;
		}
		int result=mapper.deleteByPrimaryKey(s.getId());
		return result==0 ? false : true;
	}
	public boolean update(Standard s) {
		if(s==null) {
			return false;
		}
		int result = mapper.updateByPrimaryKey(s);
		return result==0 ? false : true;
	}
}
